package com.jinzhi.jzweb.controller;


import java.util.*;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.PeixResumeCollectDO;
import com.jinzhi.jzweb.service.PeixResumeCollectService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2021-07-01 11:14:40 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/peixResumeCollect")
public class PeixResumeCollectController extends BaseController {
	@Autowired
	private PeixResumeCollectService peixResumeCollectService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:peixResumeCollect:peixResumeCollect")
	String PeixResumeCollect(){
	    return "jzweb/peixResumeCollect/peixResumeCollect";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:peixResumeCollect:peixResumeCollect")
	public Result<Page<PeixResumeCollectDO>> list(PeixResumeCollectDO peixResumeCollectDTO){
		// 查询列表数据
		Page<PeixResumeCollectDO> page = peixResumeCollectService.selectPage(getPage(PeixResumeCollectDO.class),
					peixResumeCollectService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				PeixResumeCollectDO obj = (PeixResumeCollectDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:peixResumeCollect:add")
	String add(){
	    return "jzweb/peixResumeCollect/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:peixResumeCollect:edit")
	String edit(@PathVariable("id") Long id,Model model){
		PeixResumeCollectDO peixResumeCollect = peixResumeCollectService.selectById(id);
		model.addAttribute("peixResumeCollect", peixResumeCollect);
	    return "jzweb/peixResumeCollect/edit";
	}
	
	@Log("添加")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:peixResumeCollect:add")
	public Result<String> save( PeixResumeCollectDO peixResumeCollect){
		peixResumeCollectService.insert(peixResumeCollect);
        return Result.ok();
	}
	
	@Log("修改")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:peixResumeCollect:edit")
	public Result<String>  update( PeixResumeCollectDO peixResumeCollect){
		boolean update = peixResumeCollectService.updateById(peixResumeCollect);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:peixResumeCollect:remove")
	public Result<String>  remove( Long id){
		peixResumeCollectService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:peixResumeCollect:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		peixResumeCollectService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
